package com.example.blew.demo.Controller;

import com.example.blew.demo.model.TablePo;
import com.example.blew.demo.service.TableService;
import com.example.blew.demo.uitl.GetDate;
import com.example.blew.demo.uitl.RrturnMesage;
import com.example.blew.demo.uitl.UUIDTOLong;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * TODO
 * </p>
 *
 * @author chaodong.zeng@pcitc.com
 * @since 2022/9/10
 */
@RestController
@RequestMapping("table")
@Api(tags = "table")
public class TableController {

    @Resource
    TableService tableService;


    @GetMapping("getPageTable")
    @ApiOperation(value = "按页获取")
    public RrturnMesage getPageTable(int current, int size){
       return tableService.selectPage(current, size);
    }

    @PostMapping("saveTable")
    @ApiOperation(value = "存储表单")
    public RrturnMesage saveTable(@RequestBody TablePo tablePo){
        tablePo.getAddress();
        tablePo.setId(UUIDTOLong.getUUIDTOLong());
        tablePo.setInstallDate(GetDate.getNewDate());
        int i = tableService.insertUser(tablePo);
        if(i==0)
        {
            return RrturnMesage.error();
        }
        return RrturnMesage.ok().data("tiao",i);
    }

    @PostMapping("addTable")
    @ApiOperation(value = "存储表单")
    public int addDate(){
        int count=0;
        for (int i = 0; i < 60; i++) {
            count+= tableService.addData();
        }
        return count;
    }







}